#include "Box2DVehicle.h"

Box2DVehicle::Box2DVehicle(b2Body* body) :
    mBody(body),
    mMaxSpeed(10.0f) // @TODO: may be it would be removed or corrected
{

}


float Box2DVehicle::getMass() const
{
    return mBody->GetMass();
}

void Box2DVehicle::setMass( float value )
{
    // I'm not sure that it's correct
    b2MassData data;
    mBody->GetMassData(&data);
    data.mass = value;

    mBody->SetMassData(&data);
}

Vector Box2DVehicle::getVelocity() const
{
    const b2Vec2& v= mBody->GetLinearVelocity();
    return Vector(v.x, v.y);
}

Vector Box2DVehicle::getPosition() const
{
    const b2Vec2& v = mBody->GetPosition();
    return Vector(v.x, v.y);
}

void Box2DVehicle::applyForce( const Vector& force )
{
    b2Vec2 v(force.x, force.y);
    mBody->ApplyForceToCenter(v);
}

float Box2DVehicle::getMaxSpeed() const
{
    return mMaxSpeed;
}

void Box2DVehicle::applySteering( const Vector& steering )
{
    b2Vec2 v(steering.x, steering.y);
    mBody->SetLinearVelocity(mBody->GetLinearVelocity() + v);
}

void Box2DVehicle::setAngle( float angle )
{
    mBody->SetTransform(mBody->GetPosition(), angle);
}

